Rethink time interpolation in arcdist in light of better time functions.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 22 Jul 2013 03:55:56 +0000 (03:55 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 22 Jul 2013 03:55:56 +0000 (03:55 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4464 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/arcdist.cc

index b2812494fed04bbc8f7b281b0f1362f155a13a6b..60239360e177dfe67a0210ed51e04e469c8e2268 100644 (file)
@@ -235,28 +235,19 @@ arcdist_process(void)
           /* Interpolate time */
           if (ptsopt) {
             wp->creation_time = ed->arcpt2->creation_time;
-            wp->microseconds = ed->arcpt2->microseconds;
           } else {
-            double wptimes = ed->arcpt1->creation_time +
-              ed->frac * (ed->arcpt2->creation_time - ed->arcpt1->creation_time);
-            wp->creation_time = floor(wptimes);
-            wp->microseconds = 1000000.0 * (wptimes - wp->creation_time);
-            if (ed->arcpt1->microseconds <=  ed->arcpt2->microseconds) {
-              wp->microseconds += ed->arcpt1->microseconds +
-                ed->frac * (ed->arcpt1->microseconds - ed->arcpt1->microseconds);
-            } else {
-              wp->microseconds += ed->arcpt1->microseconds +
-                ed->frac * (1000000 - ed->arcpt1->creation_time +
-                            ed->arcpt2->creation_time);
-              wp->creation_time--;
-            }
-
-            wp->creation_time += wp->microseconds / 1000000;
-            wp->microseconds %= 1000000;
+            // Apply the multiplier to the difference between the times 
+            // of the two points.   Add that to the first for the 
+            // interpolated time.
+            int scaled_time = ed->frac * 
+                  ed->arcpt1->creation_time.msecsTo(ed->arcpt2->creation_time);
+            QDateTime new_time(ed->arcpt1->creation_time.addMSecs(scaled_time));
+            wp->SetCreationTime(new_time);
           }
         }
         if (global_opts.debug_level >= 1) {
-          warning("Including waypoint %s at dist:%f lat:%f lon:%f\n", wp->shortname, ed->distance, wp->latitude, wp->longitude);
+          warning("Including waypoint %s at dist:%f lat:%f lon:%f\n", 
+                  wp->shortname, ed->distance, wp->latitude, wp->longitude);
         }
       }
       xfree(ed);